package com.moli.iov.admin.web.controller;

import com.moli.iov.admin.model.vo.req.VehicleFenceVo;
import com.moli.iov.admin.service.VehicleFenceService;
import com.moli.iov.base.model.dto.req.VehicleFenceReqDto;
import com.moli.iov.base.model.dto.res.VehicleFenceResDto;
import com.moli.iov.model.dto.req.PageExtend;
import com.moli.iov.rest.RestResponse;
import com.moli.iov.util.CommonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 车辆监控 > 电子围栏
 *
 * @author whl
 */
@Slf4j
@RequestMapping("/monitor/fenceManagement/vehicleFence")
@RestController
public class VehicleFenceController extends BaseController {

  @Autowired
  private VehicleFenceService vehicleFenceService;

  /**
   * 围栏列表
   */
  @PostMapping("/list")
  public RestResponse  listVehicleFence(
      @Validated() @RequestBody VehicleFenceVo vo) {
    assembleUserInfo(vo);
    VehicleFenceReqDto dto = new VehicleFenceReqDto();
    CommonUtils.copyProperties(vo, dto);
    RestResponse<PageExtend<VehicleFenceResDto>> iPageRestResponse = vehicleFenceService
        .listVehicleFence(dto);
    return  iPageRestResponse;
  }

  /**
   * 添加围栏
   */
  @PostMapping("/save")
  public RestResponse saveVehicleFence(
      @Validated({VehicleFenceVo.Save.class}) @RequestBody VehicleFenceVo vo) {
    assembleUserInfo(vo);
    VehicleFenceReqDto dto = new VehicleFenceReqDto();
    CommonUtils.copyProperties(vo, dto);
    return vehicleFenceService.saveVehicleFence(dto);
  }

  /**
   * 修改围栏
   */
  @PostMapping("/update")
  public RestResponse updateVehicleFence(
      @Validated({VehicleFenceVo.Update.class}) @RequestBody VehicleFenceVo vo) {
    assembleUserInfo(vo);
    VehicleFenceReqDto dto = new VehicleFenceReqDto();
    CommonUtils.copyProperties(vo, dto);
    return vehicleFenceService.updateVehicleFence(dto);
  }

  /**
   * 删除围栏
   */
  @PostMapping("/delete")
  public RestResponse deleteVehicleFence(
      @Validated({VehicleFenceVo.Delete.class}) @RequestBody VehicleFenceVo vo) {
    assembleUserInfo(vo);
    VehicleFenceReqDto dto = new VehicleFenceReqDto();
    CommonUtils.copyProperties(vo, dto);
    return vehicleFenceService.deleteVehicleFence(dto);
  }
  /**
   * 重绘
   */
 @PostMapping("/redraw")
 public RestResponse redrawVehicleFence( @Validated({VehicleFenceVo.Redraw.class}) @RequestBody VehicleFenceVo vo){
   assembleUserInfo(vo);
   VehicleFenceReqDto dto = new VehicleFenceReqDto();
   CommonUtils.copyProperties(vo, dto);
   return vehicleFenceService.redrawVehicleFence(dto);
 }




}
